package com.masterclient.app.businessmodule.homemodule.view.adapter.recommand;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;

import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.businessmodule.homemodule.bean.shoplist.ProductHomeMessage;
import com.masterclient.app.widget.StaggeredGridNoScrollLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class HomePageFootRecycleHelper {

    private Context mContext;
    private List<ProductHomeMessage> shHotProductList = new ArrayList<>();
    private RecyclerView hotRecyclerView;
    private HomeGoodsRecyclerAdapter goodsRecyclerAdapter;

    public HomePageFootRecycleHelper(Context context,String title) {
        this.mContext = context;

        hotRecyclerView = new RecyclerView(mContext);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        hotRecyclerView.setLayoutParams(layoutParams);
        StaggeredGridNoScrollLayoutManager layoutManager = new StaggeredGridNoScrollLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        hotRecyclerView.setLayoutManager(layoutManager);
        hotRecyclerView.setItemAnimator(null);
        if (hotRecyclerView.getItemDecorationCount() == 0) {
            hotRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                    super.getItemOffsets(outRect, view, parent, state);
                    outRect.set(ScreenUtils.dp2px(4), ScreenUtils.dp2px(9), ScreenUtils.dp2px(5), 0);
                }
            });
            goodsRecyclerAdapter = new HomeGoodsRecyclerAdapter();
            goodsRecyclerAdapter.setStrings("首页", title);
            hotRecyclerView.setAdapter(goodsRecyclerAdapter);
            goodsRecyclerAdapter.bindToRecyclerView(hotRecyclerView);
            goodsRecyclerAdapter.setNewData(shHotProductList);
        }
    }

    public RecyclerView getHotRecyclerView() {
        return hotRecyclerView;
    }

    public void addData(List<ProductHomeMessage>productMessageList) {
        goodsRecyclerAdapter.addData(productMessageList);
    }
}
